<?php
	class AlbumAction extends CommonAction {
		private $album;
		function __construct(){
			parent::__construct();
			$this->album=new AlbumModel();
		}
		function add($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '提示: 带<span class="red_font">*</span>的项目为必填信息. ');
			}else{
				$this->message($status,$tmess);
			}
			//记住选择的操作
			if(isset($_POST["jz"])){
				$this->assign("jz", "checked");
				$this->assign("select",$this->album->buildSelect("pid", $_POST["pid"]));
			}else{
				$this->assign("select",$this->album->buildSelect("pid"));
			}
			
			$this->display("admin/album/add.tpl");
		}

		function insert(){
			if($this->album->validateForm()){
				if($this->album->catAdd($_POST)){
					$this->add($this->album->getMessList(),1);
				}else{
					$this->assign("post", $_POST);
					$this->add($this->album->getMessList(),0);
				}
				
			}else{
				$this->assign("post", $_POST);
				$this->add($this->album->getMessList(),0);
			
			}
		}

		function edit($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '提示：根相册不能删除.<br>注意：删除相册时会删除该相册下所有子相册和图片,请慎重操作. ');
			}else{
				$this->message($status,$tmess);
			}
		
			$this->assign("list", $this->album->parseTree());
			$this->display("admin/album/edit.tpl");
		}

		function mod($tmess=null,$status=1){
			if(empty($tmess)){
				$this->assign("tmess", '提示: 带<span class="red_font">*</span>的项目为必填信息. ');
			}else{
				$this->message($status,$tmess);
			}
			if($status)
				$album=$this->album->find($_REQUEST["id"]);
			else
				$album=$_POST;
			$this->assign("select", $this->album->buildSelect("pid", $this->album->getPid($album["path"])));
			$this->assign("post", $album);
			$this->display("admin/album/mod.tpl");
		}

		function update(){
			if($this->album->validateForm($_POST)){
				if($this->album->catMod($_POST)){
					$this->mod($this->album->getMessList(),1);
				}else{
					$this->mod($this->album->getMessList(),0);
				}
			
			}else{
				$this->mod($this->album->getMessList(),0);
			}
		
		}
		function del(){
			if($this->album->remove($_GET["id"])){
				$this->edit($this->album->getMessList(),1);
			}else{
				$this->edit($this->album->getMessList(),0);
			}
		}

	}
